package com.emep.changzhi.analyse.http.datamonitor.realtime;

import com.emep.changzhi.analyse.entity.datamonitor.realtime.FoodFumeRealtime;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.datamonitor.realtime.FoodFumeRealtimeService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Wangcc
 * @version V1.0
 * @Description: 餐饮油烟监测_实时数据控制器
 * @date 2018/2/27 14:21
 */
@RequestMapping("foodfumerealtime")
@RestController
@Api(value="餐饮油烟监测_实时数据controller",tags={"餐饮油烟监测_实时数据"})
public class FoodFumeRealtimeController {


    @Autowired
    private FoodFumeRealtimeService foodFumeRealtimeService;

    /**
     * 新增餐饮油烟监测_实时数据
     * @param payload
     * @return
     */
    @ApiOperation(value="新增餐饮油烟监测_实时数据", notes="新增餐饮油烟监测_实时数据")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改时传的id", required = false, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "areaCode", value = "行政区划", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "mn", value = "设备mn号", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "packetDate", value = "报文时间", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "SO2_value", value = "污染物简称_检测值", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "SO2_vStatus", value = "污染物简称_状态", required = true, dataType = "String",paramType="query")
    })
    @PostMapping(value = "add")
    public ResultBean<FoodFumeRealtime> add(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "areaCode","mn","packetDate","SO2_value","SO2_status");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.boolAdd(foodFumeRealtimeService.save(payload)) ;
        }
        return  result;
    }

    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="首页", notes="首页")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "home")
    public List<FoodFumeRealtime> findFoodFumeRealtimeByHome(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            return foodFumeRealtimeService.findFoodFumeRealtimeByHome(Integer.parseInt(payload.get("pageSize").toString()));
        }
        return  null;
    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="翻页查询", notes="翻页查询")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "查询起始id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "Integer",paramType="query")
    })
    @GetMapping(value = "flip")
    public List<FoodFumeRealtime> findFoodFumeRealtimeByFlip(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "id","pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return foodFumeRealtimeService.findFoodFumeRealtimeByFlip(payload.get("id").toString() , Integer.parseInt(payload.get("pageSize").toString()));
        }
        return null;
    }

}
